import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/pages/Home.vue'
import Category from '@/pages/Category.vue'
import Shopcart from '@/pages/Shopcart.vue'
import User from '@/pages/User.vue'
import Login from '@/pages/user/Login.vue'
import Register from '@/pages/user/Register.vue'
import GoodsList from '@/pages/goods/GoodsList.vue'
import GoodsInfo from '@/pages/goods/GoodsInfo.vue'

Vue.use(VueRouter)

const routes = [
	//设置标题
      { path: '/', redirect: '/home', meta: { title: '首页' } },
      { path: '/home', component: Home, name: 'home', meta: { title: '首页' } },
	  { path: '/category', component: Category, name: 'category', meta: { title: '分类' } },
	  { path: '/shopcart', component: Shopcart, name: 'shopcart', meta: { title: '购物车' } },
	  { path: '/user', component: User, name: 'user', meta: { title: '我的' } },
	  { path: '/user/login', component: Login, name: 'login', meta: { title: '登录' } },
	  { path: '/user/register', component: Register, name: 'register', meta: { title: '注册' } },
	  { path: '/category/goodslist/:category_id', component: GoodsList, props: true, name: 'goods_list', meta: { title: '商品列表' } },
	  { path: '/category/goodsinfo/:id', component: GoodsInfo, props: true, name: 'goods_info', meta: { title: '商品信息' } }
]

const router = new VueRouter({
  routes,
  linkActiveClass: 'mui-active'
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
